<template>
	<view class="mainpadding2">
		<view class="flexcolumn" v-if="list.data.length==0">
			<view class="placeholderimage" style="margin-top: 100rpx;"></view>
			<view class="xiaohui margin_top main_size">暂无数据</view>
		</view>
		<view class="mainpadding ffffff shadow radius margin_top flextop" v-for="item in list.data" :key="item.id" @click="tzcxxq(item.id)">
			<image  style="width: 230rpx;height: 170rpx;" :src="item.image_text" mode=""></image>
			<view class="flexcolumnbet" style="width: 60%;height: 170rpx;">
				<view class="titletext zhonghei fonweight yhxk" style="width: 300rpx;">{{item.name}}</view>
				<view class="flexleft ">
					<view class="margin_right1">
						<u-icon name="map" size="16"></u-icon>
					</view>
					<view class="ershil xiaohei yhxk" style="width: 300rpx;">{{item.detail}}</view>
				</view>
				<view class="flexbetween" style="width: 100%;">
					<view class="">
						<text class="strongtext xiaohong">￥</text>
						<text class="bigtext xiaohong fonweight">{{item.salesprice}}</text>
						<text class="xiaohong strongtext">起</text>
					</view>
					<view class="strongtext xiaohui">{{returnKmUnit(Number(item.distance))}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				lat: "",
				lng: "",
			}
		},
		onLoad() {
			this.getLocation()
			// #ifdef H5
			this.init()
			// #endif
		},
		methods: {
			getLocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						console.log(res, "获取定位成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.init()
					},
					fail(err) {
						uni.hideLoading()
						console.log(err, 23432);
					}
				});
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					lat:this.lat,
					lng:this.lng,
				}
				let url = '/api/carshopcl/carshopIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转商家详情
			tzcxxq(id){
				uni.navigateTo({
					url:'/pages_index/shangjiaxqchelwh?id='+id
				})
			}
		}
	}
</script>

<style>

</style>
